package gui;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import fiziksobject.*;

import physics.*;

public class ForcerCreator extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ForcerCreator thiz = this;
	public ForcerCreator() {
		String[] options = {"Gravity", "Constant Magnetic Field", "Constant Electric Field", "Spring" };
		final JList list = new JList(options);
		JButton ok = new JButton("Ok");
		setLayout(new BorderLayout());
		add(list,BorderLayout.CENTER);
		add(ok,BorderLayout.SOUTH);
		ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String select = (String) list.getSelectedValue();
				Forcer ret = null;
				if(select==null) {
					return;
				}
				if(select.equals("Gravity")) {
					ret = new Gravity(new Vector());
				}
				else if(select.equals("Constant Magnetic Field")) {
					ret = new magneticField(0,true);
				}
				else if(select.equals("Constant Electric Field")) {
					ret = new electricField(new Vector());
				}
				else if(select.equals("Spring")){
					ret = new Springs(0, new Location(0,0), null);
				}
				PhysicsEngine.getPhysicsEngine().addForcer(ret);
				ForcerEditor fe = ForcerEditorManager.get().getEditor(ret);
				fe.setSize(233,377);
				fe.setVisible(true);
				WindowEvent wev = new WindowEvent(thiz, WindowEvent.WINDOW_CLOSING);
                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
			}
		});
	}
}
